package com.rrx.service;

import com.rrx.mapper.MenuMapper;
import com.rrx.model.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class MenuService {
    @Autowired
    MenuMapper menuMapper;

    public boolean isMenuExists(String name) {
        if(menuMapper.isMenuExists(name) > 0)
            return true;
        return false;
    }

    public boolean addMenu(String name, String permission, int order, String request, Integer parentId) {
        int i = menuMapper.addMenu(name, permission, order, request, parentId);
        if(i > 0)
            return true;
        return false;
    }

    public Menu[] getAllFirstMenu() {
        Menu[] menus = menuMapper.getAllFirstMenu();
        return menus;
    }

    public Menu getFirstMenuById(int id) {
        Menu menu = menuMapper.getFirstMenuById(id);
        return menu;
    }

    public Menu[] getSecondMenuById(int id) {
        Menu[] menus = menuMapper.getSecondMenuById(id);
        System.out.println(menus.length);
        for(Menu m : menus) {
            System.out.println(m.getMenuPermission());
        }
        return menus;
    }
    public Menu getMenuByPermission(String permission) {
        Menu menu = menuMapper.getMenuByPermission(permission);
        return menu;
    }

    public Menu[] getAdminMenusById(int id) {
        Menu[] menus = menuMapper.getAdminMenusById(id);
        return menus;
    }
}
